package org.ielts.action;

import static com.yifeng.struts2.ResultParameters.*;
import static com.yifeng.struts2.ResultConstants.*;
import static com.yifeng.struts2.ActionUtils.*;

import java.util.Date;

import org.ielts.domain.base.Course;
import org.ielts.domain.base.SignCourse;
import org.ielts.domain.base.Student;
import org.ielts.domain.log.SignCourseLog;
import org.ielts.domain.security.User;
import org.ielts.service.ConsultantService;
import org.ielts.service.CourseService;
import org.ielts.service.SchoolService;
import org.ielts.service.SignCourseService;
import org.ielts.service.StudentService;
import org.ielts.service.TutorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import com.yifeng.modules.annotations.Operation;
import com.yifeng.page.table.Paginations;
import com.yifeng.utils.JsonResultBuilder;
import com.yifeng.utils.PageUtils;
import com.yifeng.web.Pagers;

public class SchoolAction extends BaseAction {

	@Autowired
	SchoolService schoolService;

	@Operation(result = FILL)
	public String createFreezeLog() {

		String studentId = form.readString("studentId");
		String signId = form.readString("signId");

		put("studentId", studentId);
		put("signId", signId);

		return FILL;
	}

	@Operation(result = JSON)
	public String doFinishCourse() {

		String studentId = form.readString("studentId");
		String title = form.readString("title");
		String signId = form.readString("signId");

		schoolService.finishCourse(studentId, signId, title);
		setJson(JsonResultBuilder.success(true).msg("操作成功").json());

		return JSON;
	}

	@Operation(result = JSON)
	public String doResumeCourse() {
		String studentId = form.readString("studentId");
		String title = form.readString("title");
		String signId = form.readString("signId");

		schoolService.resumeCourse(studentId, signId, title);
		setJson(JsonResultBuilder.success(true).msg("操作成功").json());

		return JSON;
	}

	@Operation(result = JSON)
	public String doFreezCourse() {
		String studentId = form.readString("studentId");
		String title = form.readString("title");
		String signId = form.readString("signId");

		Date resumeDate = valueReader.name("resumeDate").dateValue("yyyy-MM-dd");
		Date endDate = valueReader.name("endDate").dateValue("yyyy-MM-dd");

		schoolService.freezCourse(studentId, signId, resumeDate, endDate, title);

		setJson(JsonResultBuilder.success(true).msg("操作成功").json());

		return JSON;
	}

	@Autowired
	ConsultantService consultantService;

	@Operation(result = FILL)
	public String selectConsultor() {

		Iterable<User> users = consultantService.listConsultant();
		put("users", users);

		return FILL;
	}

	@Autowired
	TutorService tutorService;

	@Operation(result = FILL)
	public String selectTutor() {
		Iterable<User> users = tutorService.listTutor();
		put("users", users);

		return FILL;
	}
}
